package com.Txunda.fxw.ui.activity.other;


import java.util.Map;

import com.Txunda.fxw.R;
import com.Txunda.fxw.base.utils.util.JSONUtils;
import com.Txunda.fxw.ui.base.BaseAty;
import com.Txunda.fxw.ui.http.AboutUs;
import com.Txunda.fxw.view.dialog.AlertDialog;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

/**
 * 客服热线
 *
 * @author Administrator
 */
public class HotLineAty extends BaseAty {

    @ViewInject(R.id.aty_title3_tv_center)
    private TextView aty_title3_tv_center;
    @ViewInject(R.id.btn_mine_call)
    private TextView btn_mine_call;
    private AboutUs aboutUs;
    @ViewInject(R.id.tv_mine_hours)
    private TextView tv_mine_hours;
    @ViewInject(R.id.tv_call_email)
    private TextView tv_call_email;
    @ViewInject(R.id.tv_call_xinxiang)
    private TextView tv_call_xinxiang;
    @ViewInject(R.id.tc_call_youbian)
    private TextView tc_call_youbian;
    @ViewInject(R.id.tv_call_shouxin)
    private TextView tv_call_shouxin;
    private String service_tel;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        showProgressDialog();
        aboutUs.service(this);
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.aty_hot_line_aty;
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void onComplete(String requestUrl, String jsonStr) {
        super.onComplete(requestUrl, jsonStr);
        if (requestUrl.contains("service")) {
            Map<String, String> map = JSONUtils.parseKeyAndValueToMap(jsonStr);
            if ("success".equals(map.get("flag"))) {
                Map<String, String> data = JSONUtils.parseKeyAndValueToMap(map.get("data"));
                String tel_time = data.get("tel_time");   //办公时间
                String email = data.get("email");   //email
                String email_address = data.get("email_address");   //email地址
                String postcode = data.get("postcode");   //邮编
                String receiver = data.get("receiver");   //收件人
                service_tel = data.get("service_tel");
                btn_mine_call.setText(service_tel);
                tv_mine_hours.setText(tel_time);
                tv_call_email.setText("客服邮箱: " + email);
                tv_call_xinxiang.setText("信箱地址: " + email_address);
                tc_call_youbian.setText("邮编: " + postcode);
                tv_call_shouxin.setText("收信人: " + receiver);

            }
        }
    }

    @Override
    @OnClick({R.id.btn_mine_call})
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.btn_mine_call:   //拨打电话
                try {
                    new AlertDialog(this).builder().setTitle("提示").setMsg("tel: " + btn_mine_call.getText().toString())
                            .setPositiveButton("确认", new View.OnClickListener() {

                                @Override
                                public void onClick(View v) {
                                    Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel: " + btn_mine_call.getText().toString()));
                                    startActivity(intent);

                                }
                            }).setNegativeButton("取消", new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {

                        }
                    }).show();

                } catch (NullPointerException e) {
                    e.printStackTrace();
                }
                break;

            default:
                break;
        }
    }

    @Override
    protected void initialized() {
        aty_title3_tv_center.setText("客服热线");
        aboutUs = new AboutUs();
    }

    @Override
    protected void requestData() {

    }


}
